﻿import com.dmotiko.general.*
import com.dmotiko.util.MathUtils;
import com.dmotiko.zonaoutlet.*
import flash.display.*;
import mx.transitions.*;
import mx.transitions.easing.*;
import mx.utils.Delegate;

class ZOAddressOutlet
extends BaseClip {
	
	/* FLA VARS */
	private var mcMap:MovieLoaderClip;
	private var txtAddress:TextField;
	private var mcAddressSep:MovieClip;
	private var txtPhone:TextField;
	private var mcPhoneSep:MovieClip;
	private var txtSchedule:TextField;
	private var mcScheduleSep:MovieClip;
	private var txtURL:TextField;
	private var mcURLSep:MovieClip;
	private var txtPay:TextField;
	private var mcPay:MovieLoaderClip;
	private var mcPaySep:MovieClip;
	private var btnPromos:ButtonClip;
		
	private function initClip():Void {
		txtAddress.text = txtPhone.text = txtSchedule.text = txtURL.text = "";
		txtAddress.autoSize = txtPhone.autoSize = txtSchedule.autoSize = txtURL.autoSize = "left";
	}
	
	private function refreshData():Void {
		txtAddress.text = data.address;
		mcAddressSep._y = txtAddress._y + txtAddress._height + 2;
		
		txtPhone.text = data.phone;
		txtPhone._y = mcAddressSep._y + mcAddressSep._height + 2;
		mcPhoneSep._y = txtPhone._y + txtPhone._height + 2;
		
		txtSchedule.text = data.schedule;
		txtSchedule._y = mcPhoneSep._y + mcPhoneSep._height + 2;
		mcScheduleSep._y = txtSchedule._y + txtSchedule._height + 2;
		
		txtURL.html = true;
		txtURL.htmlText = "<a href='"+data.url+"' target='_blank'>"+data.urlLabel+"</a>";
		txtURL._y = mcScheduleSep._y + mcScheduleSep._height + 2;
		mcURLSep._y = txtURL._y + txtURL._height + 2;
		
		txtPay.text = data.pay;
		txtPay._y = mcURLSep._y + mcURLSep._height + 2;
		
		mcPay._y = txtPay._y + txtPay._height - 2;
	}
	
	private function childLoaded( evnt ) {
		if ( data.mapSrc && evnt.target == mcMap ) {
			mcMap.addEventListener( MovieLoaderClip.CLIP_LOADED, Delegate.create( this, fadeMap ) );
			mcMap.loadContent( data.mapSrc );
		} else if (data.paySrc && evnt.target == mcPay) {
			mcPay.addEventListener( MovieLoaderClip.CLIP_LOADED, Delegate.create( this, layoutPay ) );
			mcPay.loadContent( data.paySrc );
		}
	}
	
	private function fadeMap( evnt ) {
		registerTween( "mapFade", new Tween( evnt.clip, "_alpha", Regular.easeOut, 0, 100, 0.5, true) );
		evnt.clip._rotation = -2;
		new Tween( evnt.clip, "_rotation", Elastic.easeOut, -2, 0, 1, true);
	}
	
	private function layoutPay( evnt ) {
		registerTween( "payFade", new Tween( evnt.clip, "_alpha", Regular.easeOut, 0, 100, 0.5, true) );
		mcPaySep._y = mcPay._y + mcPay._height + 4;
	}
	
}